/**
 * Created by Administrator on 2017/6/21 0021.
 */
var F_Save_Entrance = {
    _init: function () {
        if (B_Login._checkUpdate(), M_HeadFoot._headShow(1), "demo" != M_Init._controller && B_User._isDemoUser()) B_Login._openLogin("background"); else {
            switch (M_Init._clean(), M_Init._controller) {
                case"demo":
                    M_Init._api.innerOperationRetentionUser = "demoInnerOperationRetentionUser";
                    break;
                default:
                    M_Init._api.innerOperationRetentionUser = "innerOperationRetentionUser"
            }
            M_Init._dateCache.begin = M_Init._dateChoose.begin, M_Init._dateCache.end = M_Init._dateChoose.end, M_Common._getOrderGame("save", "", "1-2-3"), B_Date._chooseSection({
                autoCommit: !1,
                todayValid: !1
            }, 1, M_Init._dateChoose.begin, M_Init._dateChoose.end, function (e, a) {
                e == M_Init._dateCache.begin && M_Init._dateCache.end == a || (M_Init._dateCache.begin = e, M_Init._dateCache.end = a, F_Save_Info._getInfo())
            })
        }
    }
}, F_Save_Info = {
    _init: [{
        type: "togetherTab",
        name: "新增帐户留存",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["以昨日的新增玩家为基数，昨日新增玩家在今日仍有登录记录的人数", "以6日前的新增玩家为基数，这批新增玩家在今日仍有登录记录的人数", "以29日前的新增玩家为基数，这批新增玩家在今日仍有登录记录的人数"]
        }]
    }, {
        type: "switchTab",
        name: "当日游戏次数分布",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["昨日新增玩家中，今日也有登录的玩家在当日的游戏次数分布", "6日前的新增玩家中，今日也有登录的玩家在当日的游戏次数分布", "29日前的新增玩家中，今日也有登录的玩家在当日的游戏次数分布"]
        }]
    }, {
        type: "switchTab",
        name: "当日游戏时长分布",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["昨日新增玩家中，今日也有登录的玩家在当日的游戏时长分布", "6日前的新增玩家中，今日也有登录的玩家在当日的游戏时长分布", "29日前的新增玩家中，今日也有登录的玩家在当日的游戏时长分布"]
        }]
    }, {
        type: "switchTab",
        name: "当日等级分布",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["昨日新增玩家中，今日也有登录的玩家在当日的等级分布", "6日前的新增玩家中，今日也有登录的玩家在当日的等级分布", "29日前的新增玩家中，今日也有登录的玩家在当日的等级分布"]
        }]
    }, {
        type: "switchTab",
        name: "中国地区分布",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["昨日新增玩家中，今日也有登录的玩家的地区分布", "6日前的新增玩家中，今日也有登录的玩家的地区分布", "29日前的新增玩家中，今日也有登录的玩家的地区分布"]
        }]
    }, {
        type: "switchTab",
        name: "全球地区分布",
        tab: ["次日留存", "7日留存", "30日留存"],
        tips: [{}, {
            position: "second",
            content: ["昨日新增玩家中，今日也有登录的玩家的地区分布", "6日前的新增玩家中，今日也有登录的玩家的地区分布", "29日前的新增玩家中，今日也有登录的玩家的地区分布"]
        }]
    }],
    _port: [[[{name: "次日留存数", key: "y_axis_retention_num_1d"}, {
        name: "次日留存率",
        key: "y_axis_retention_rate_1d"
    }], [{name: "7日留存数", key: "y_axis_retention_num_7d"}, {
        name: "7日留存率",
        key: "y_axis_retention_rate_7d"
    }], [{name: "30日留存数", key: "y_axis_retention_num_30d"}, {
        name: "30日留存率",
        key: "y_axis_retention_rate_30d"
    }]], [[{name: "次日留存", key: "logintimes_distri|1d"}], [{name: "7日留存", key: "logintimes_distri|7d"}], [{
        name: "30日留存",
        key: "logintimes_distri|30d"
    }]], [[{name: "次日留存", key: "oltime_distri|1d"}], [{name: "7日留存", key: "oltime_distri|7d"}], [{
        name: "30日留存",
        key: "oltime_distri|30d"
    }]], [[{name: "次日留存", key: "level_distri|1d"}], [{name: "7日留存", key: "level_distri|7d"}], [{
        name: "30日留存",
        key: "level_distri|30d"
    }]], [[{name: "次日留存", key: "area_distri|1d|china"}], [{name: "7日留存", key: "area_distri|7d|china"}], [{
        name: "30日留存",
        key: "area_distri|30d|china"
    }]], [[{name: "次日留存", key: "area_distri|1d|global"}], [{
        name: "7日留存",
        key: "area_distri|7d|global"
    }], [{name: "30日留存", key: "area_distri|30d|global"}]]],
    _domInit: function () {
        M_Inside._htmlChartTable($("#ct_main_area"), F_Save_Info._init), M_Inside._downloadCsv(), F_Save_Info._getInfo()
    },
    _getInfo: function () {
        for (var e = M_Init._dateCache.begin, a = M_Init._dateCache.end, t = [], n = 0; n < F_Save_Info._init.length; n++)t.push("bs_chart_" + n + "_0");
        var i = {};
        i.start_date = e, i.end_date = a, i.game_id = M_Init._gameId, i = B_Common._postData(i), B_Port._ajax(M_Init._api.innerOperationRetentionUser, "post", !0, i, function () {
            for (var e = 0; e < t.length; e++)$("#" + t[e]).html(B_Pre._loading())
        }, function () {
            for (var e = 0; e < t.length; e++)$("#" + t[e]).html("")
        }, function (e, a) {
            if (e) {
                M_Init._dataCache.data = e;
                for (var t = 0; t < F_Save_Info._init.length; t++)if (F_Save_Info._init[t].tab.length > 0) {
                    M_Init._dataCache["position_" + t] || (M_Init._dataCache["position_" + t] = 0);
                    for (var n = 0; n < F_Save_Info._init[t].tab.length; n++)if (M_Init._dataCache["position_" + t] == n) {
                        F_Save_Info._chartHtml(t, n), M_Inside._chartTableIcon(F_Save_Info._init[t].type, t, n);
                        break
                    }
                    M_Inside._tabChangePerChart(t, F_Save_Info._init[t].type, "save")
                }
            }
        }, function (e, a, n) {
            for (var i = 0; i < t.length; i++)$("#" + t[i]).html(B_Pre._empty(a))
        })
    },
    _chartHtml: function (e, a) {
        M_Init._dataCache["position_" + e] = a;
        var t = M_Init._dataCache.data, n = {x_axis: [], y_axis: [], yFormat: ""}, i = {}, _ = 50, o = "";
        switch (e + "") {
            case"0":
                n.xFormatDate = !0, n.yDouble = !0, n.yDoubleLabel = ["", "%"], n.tooltip = {
                    type: "diff",
                    num: 2,
                    unit: ["人", "%"]
                }, i = {head: ["日期"], body: []}, o = "%";
                break;
            case"1":
            case"2":
            case"3":
            case"4":
            case"5":
                n.tooltip = {num: 1, unit: "人"}
        }
        for (var s = 0; s < F_Save_Info._port[e][a].length; s++) {
            var d = F_Save_Info._port[e][a][s].key.split("|"), r = F_Save_Info._port[e][a][s].name;
            if (1 == e) {
                if (_ = 20, i = {head: ["游戏次数", r + "(人)", "玩家占比"], body: []}, t[d[0]][d[1]]) {
                    for (var h = t[d[0]][d[1]], m = [], l = 0; l < h.length; l++)n.x_axis.push(h[l].login_times + "次"), m.push(h[l].user_num), i.body[l] || (i.body[l] = [h[l].login_times + "次"]), i.body[l].push(h[l].user_num), i.body[l].push(h[l].user_rate + "%");
                    n.y_axis.push({name: r, data: m})
                }
            } else if (2 == e) {
                if (_ = 20, i = {head: ["已玩天数", r + "(人)", "玩家占比"], body: []}, t[d[0]][d[1]]) {
                    for (var h = t[d[0]][d[1]], m = [], l = 0; l < h.length; l++)h[l].oltime_classify = h[l].oltime_classify.replace("&gt;", ">"), h[l].oltime_classify = h[l].oltime_classify.replace("&lt;", "<"), n.x_axis.push(h[l].oltime_classify), m.push(h[l].user_num), i.body[l] || (i.body[l] = [h[l].oltime_classify]), i.body[l].push(h[l].user_num), i.body[l].push(h[l].user_rate + "%");
                    n.y_axis.push({name: r, data: m})
                }
            } else if (3 == e) {
                if (_ = 40, i = {head: ["玩家等级分布", r + "(人)", "玩家占比"], body: []}, t[d[0]][d[1]]) {
                    for (var h = t[d[0]][d[1]], m = [], l = 0; l < h.length; l++)n.x_axis.push(h[l].level + "级"), m.push(h[l].user_num), i.body[l] || (i.body[l] = [h[l].level + "级"]), i.body[l].push(h[l].user_num), i.body[l].push(h[l].user_rate + "%");
                    n.y_axis.push({name: r, data: m})
                }
            } else if (4 == e || 5 == e) {
                if (_ = 20, i = {
                        head: ["地区", r + "(人)", "玩家占比"],
                        body: []
                    }, t[d[0]] && t[d[0]][d[1]] && t[d[0]][d[1]][d[2]]) {
                    for (var h = t[d[0]][d[1]][d[2]], m = [], l = 0; l < h.length; l++)n.x_axis.push(h[l].area_classify), m.push(h[l].user_num), i.body[l] || (i.body[l] = [h[l].area_classify]), i.body[l].push(h[l].user_num), i.body[l].push(h[l].user_rate + "%");
                    n.y_axis.push({name: r, data: m})
                }
            } else if (_ = 50, n.x_axis = t.x_axis, s + "" == "0" ? i.head.push(r + "(人)") : i.head.push(r), t[d[0]]) {
                for (var h = t[d[0]], l = 0; l < h.length; l++)i.body[l] || (i.body[l] = [t.x_axis[l]]), s + "" == "0" ? i.body[l].push(h[l]) : i.body[l].push(h[l] + o);
                0 == s ? n.y_axis.push({type: "bar", name: r, data: h}) : n.y_axis.push({
                    type: "line",
                    name: r,
                    data: h
                })
            }
        }
        i.name = M_Inside._tableName(F_Save_Info._init, e, a, M_Init._dateCache.begin, M_Init._dateCache.end), a = 0, M_Init._dataCache[e + "_" + a] = i, M_Inside_Chart._chartData(_, "bs_chart_" + e + "_" + a, n), M_Inside._tableHtml(1, e + "_" + a)
    }
};